/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.util.Collection;
import java.util.TreeSet;

/**
 *
 * @author sio
 */
public class Pays {

    private Collection<Dep> lesDeps;
    private Collection<Spe> lesSpes;

    public Pays() {
        lesDeps = DAO.getLesDeps();
        lesSpes = DAO.getLesSpes();
        Collection<Med> lesMeds = DAO.getLesMeds();
        for (Med unMed : lesMeds) {
            if (unMed.getSpe() != null){
            for (Spe unSpe : lesSpes) {
                if (unMed.getSpe().equals(unSpe.getNom())) {
                    unSpe.addMed(unMed);
                }

            }
        }
            for (Dep unDep : lesDeps){
                if (unDep.getNum().equals(unMed.getDep())){
                    unDep.addDep(unMed);
                }
            }
    }
    }

    public Collection<Dep> getLesDeps() {
        return this.lesDeps;
    }

    public Collection<Spe> getLesSpes() {
        return this.lesSpes;
    }

    public Dep getLeDep(String num) {
        for (Dep d : lesDeps) {
            if (d.getNum().equals(num)) {
                return d;
            }

        }
        return null;
    }
    
    public Spe getLeSpe(String nom) {
        for (Spe s : lesSpes) {
            if (s.getNom().equals(nom)) {
                return s;
            }

        }
        return null;
    }
    

    public Collection<Med> getByNom(String text) {
        Collection<Med> lesMeds = new TreeSet();
        for (Dep d : lesDeps) {
            for (Med m : d.getLesmeds()) {
                if (m.getNom().startsWith(text)) {
                    lesMeds.add(m);
                }
            }
        }

        return lesMeds;
    }
}
